<?php

declare (strict_types=1);

namespace app\controller\admin\activity\lottery;

use app\common\repositories\activity\lottery\LuckLotteryRecordRepository;
use crmeb\basic\BaseController;
use think\App;

/**
 * 抽奖中奖记录
 * Class LuckLotteryRecord
 * @package app\controller\admin\activity\lottery
 */
class LuckLotteryRecord extends BaseController
{
    protected $repository;
    /**
     * @param App $app
     * @param LuckLotteryRecordRepository $repository
     */
    public function __construct(App $app,LuckLotteryRecordRepository  $repository)
    {
        parent::__construct($app);
        $this->repository = $repository;
    }


    /**
     * 用抽奖id查询中奖记录
     * @param $id
     * @return mixed
     */
    public function index($id)
    {
        $where = $this->request->more([
            ['lottery_id', ''],
            ['is_receive', ''],
            ['is_deliver', ''],
            ['type', ''],
            ['keyword', ''],
            ['data', '', '', 'time'],
        ]);
        if (!$id) {
            return app('json')->fail('缺少活动ID');
        }
        $where['lottery_id'] = $id;
        [$page, $limit] = $this->getPage();
        return app('json')->success($this->repository->getList($where,$page, $limit));
    }

    public function list()
    {
        $where = $this->request->more([
            ['lottery_id', ''],
            ['is_receive', ''],
            ['is_deliver', ''],
            ['type', ''],
            ['keyword', ''],
            ['data', '', '', 'date'],
            ['factor', ''],
        ]);
        [$page, $limit] = $this->getPage();
        return app('json')->success($this->repository->getList($where,$page, $limit));
    }

    public function deliver($id)
    {
        $data = $this->request->params([
            ['deliver_name', ''],
            ['deliver_number', ''],
            ['mark', ''],
        ]);
        if (!$id) {
            return app('json')->fail('缺少ID');
        }
        return app('json')->success($this->repository->setDeliver((int)$id, $data) ? '处理成功' : '处理失败');
    }
}
